<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<c:if test="${empty visitor ||visitor.adminGrade > 0}">
	<c:redirect url="wel!welcome.z" />
</c:if>
<head>
	<title>用户列表</title>
	<script type="text/javascript">
	jq(function() {
		jq("button.valid").parents("form").validate({
			rules: {
			"eMailAddress.realname": {required: true},
			"eMailAddress.email": {required: true,email:true}
			}
		});
	});
	</script>
</head>

<body>
	<form class="head" action="u!toAdd.z" method="post">
		<c:if test="${visitor.adminGrade == 0}">
			<button type="submit" >
				添加新用户
			</button>
		</c:if>
	</form>

	<table class="list">
	<caption>
			用户列表
		</caption>
		<thead>
			<tr title="">
				<th>
					用户名
				</th>
				<th>
					用户等级
				</th>
				<th>
					删除用户
				</th>
			</tr>
		</thead>

		<c:forEach var="user" items="${display['users']}">
			<tr>
				<td>
					${user.username } (${user.realname })
				</td>
				<td>
				<c:if test="${user.adminGrade == 2 }">普通用户</c:if>
					<c:if test="${user.adminGrade == 1 }">超级用户</c:if> 
					<c:if test="${user.adminGrade == 0 }">管理员</c:if> 
					
					<a href="u!toUpdate.z?id=${user.id}">(点击这里修改)</a>
				</td>
				<td>
					<a href="u!delete.z?id=${user.id}" class="askAgain">删除用户</a>
				</td>
			</tr>
		</c:forEach>
	</table>
	
	<table class="list">
	<caption>
			邮件列表
		</caption>
		<thead>
			<tr title="">
				<th>
					收件人
				</th>
				<th>
					邮件地址
				</th>
				<th>
					删除
				</th>
			</tr>
		</thead>

		<c:forEach var="email" items="${display['emails']}">
			<tr>
				<td>
					${email.realname }
				</td>
				<td>
					${email.email }
				</td>
				<td>
					<a href="address!delete.z?id=${email.id}" class="askAgain">删除</a>
				</td>
			</tr>
		</c:forEach>
	</table>

	<form action="address!add.z" method="post">
		<label>
			收件人:
			<input type="text" name="eMailAddress.realname" tabindex="1" />
		</label>
		<label>
			邮件地址:
			<input type="text" name="eMailAddress.email" tabindex="2" />
		</label>
			<button type="submit" class="valid">
				添加新邮件地址
			</button>
	</form>

</body>
